package 装饰模式.商场促销实例;


/**
 * @author zyl
 * @Description
 * @since 2023/12/26 10:49
 */

public class CashReturn extends CashSuper {
    //返利条件
    private double moneyCondition = 0d;
    //返利值
    private double moneyReturn = 0d;

    public CashReturn(double moneyCondition, double moneyReturn) {
        this.moneyCondition = moneyCondition;
        this.moneyReturn = moneyReturn;
    }

    @Override
    public double acceptCash(double price, int num) {
        double result = price * num;
        if (this.moneyCondition > 0 && result > this.moneyCondition){
            result = result - this.moneyReturn * Math.floor(result / this.moneyCondition);
        }
        return super.acceptCash(result,1);
    }
}
